﻿using System;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

namespace DDD.Commont
{
    public static class AutofacContainerBuilder
    {
        public static IContainer Container { get; private set; }

        private static readonly ContainerBuilder containerBuilder;

        static AutofacContainerBuilder()
        {
            var serviceCollection = new ServiceCollection();
            containerBuilder = new ContainerBuilder();
            containerBuilder.Populate(serviceCollection);
        }

        public static void Build(Action<ContainerBuilder> register)
        {
            register(containerBuilder);
            Container = containerBuilder.Build();
        }
    }
}